using micromsg;
using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Protocol;
using MicroMsg.Storage;
using System;
namespace MicroMsg.Scene
{
	public class NetSceneGetWeiBoURL : NetSceneBaseEx<GetWeiBoURLReq, GetWeiBoURLResp, GetWeiBoURLReq.Builder>
	{
		private const string TAG = "NetSceneGetWeiBoURL";
		private DelegateNavigateToUrl navigateToUrl;
		public bool doScene(string toUserName, string toWeibousrName, DelegateNavigateToUrl delegateNavigateToUrl, AddContactScene scene = AddContactScene.MM_ADDSCENE_SEARCH_WEIXIN)
		{
			if (delegateNavigateToUrl == null)
			{
				return false;
			}
			if (string.IsNullOrEmpty(toUserName) && string.IsNullOrEmpty(toWeibousrName))
			{
				return false;
			}
			Account curAccount = AccountMgr.getCurAccount();
			if (curAccount == null)
			{
				return false;
			}
			string text = toUserName;
			string text2 = toWeibousrName;
			base.beginBuilder();
			this.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0);
			if (text == null)
			{
				text = "";
			}
			if (text2 == null)
			{
				text2 = "";
			}
			this.mBuilder.UserName = text;
			this.mBuilder.A2Key = Util.toSKBuffer(curAccount.bytesA2Key);
			this.mBuilder.BlogUserName = text2;
			this.mBuilder.Scene = (uint)scene;
			this.mSessionPack.mCmdUri = "/cgi-bin/micromsg-bin/getwburl";
			this.mSessionPack.mConnectMode = 2;
			base.endBuilder();
			this.navigateToUrl = delegateNavigateToUrl;
			return true;
		}
		protected override void onFailed(GetWeiBoURLReq request, GetWeiBoURLResp response)
		{
			Log.smethod_1("NetSceneGetWeiBoURL", "GetWeiBoURL bottle failed system error!");
			EventCenter.postEvent(EventConst.ON_NETSCENE_GETWEIBOURL_FAIL, null, null);
		}
		protected override void onSuccess(GetWeiBoURLReq request, GetWeiBoURLResp response)
		{
			if (response != null && response.BaseResponse.Ret == 0)
			{
				this.navigateToUrl(response.URL);
				EventCenter.postEvent(EventConst.ON_NETSCENE_GETWEIBOURL_SUCCESS, response.URL, null);
				return;
			}
			Log.smethod_1("NetSceneGetWeiBoURL", "GetWeiBoURL response not invalidate response.BaseResponse.Ret = " + ((RetConst)response.BaseResponse.Ret).ToString());
			EventCenter.postEvent(EventConst.ON_NETSCENE_GETWEIBOURL_FAIL, null, null);
		}
	}
}
